home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Frameworks / Grant's CGI Framework 1.0b12 / Util / CGI.h < prev    next >
C/C++ Source or Header  |  1995-12-09  |  8KB  |  282 lines

  1. #pragma once
  2. /*****
  3.  *
  4.  *    Grant's CGI Framework (Common Grant Interface :-)
  5.  *        http://arpp1.carleton.ca/grant/mac/grantscgi.html
  6.  *
  7.  *    CGI.h
  8.  *
  9.  *    standard types and function prototypes for cgi applications
  10.  *    See the Read Me or CGI.c for instructions on using the CGI Utilities
  11.  *
  12.  *    #include this file in your source files that need to access the cgi module
  13.  *
  14.  *    This is a support file for "Grant's CGI Framework".
  15.  *    Please see the license agreement that accompanies the distribution package
  16.  *    for licensing details.
  17.  *
  18.  *    Copyright ©1995 by Grant Neufeld
  19.  *
  20.  *    http://arpp1.carleton.ca/grant/
  21.  *    gneufeld@ccs.carleton.ca
  22.  *    grant@acm.org
  23.  *
  24.  *****/
  25.  
  26. #include "MyConfiguration.h"
  27. #if kCompileWithCGICode
  28.  
  29. #include <Threads.h>
  30.  
  31. /***  CONSTANT DECLARATIONS  ***/
  32.  
  33. #define kCGIParamMaxSize        32769
  34.  
  35. #define kCGIHTTPMethodGet                "GET"
  36. #define kCGIHTTPMethodPost                "POST"
  37. #define kCGIHTTPMethodGetConditional    "GET_CONDITIONAL"
  38.  
  39. #define kCGIFormFieldDelimiter    '='
  40. #define kCGIFormFieldSeparator    '&'
  41.  
  42. /* Apple events */
  43.  
  44. #define kAEClassCGI            'WWWΩ'
  45. #define kAEIDSearchDoc        'sdoc'
  46.  
  47. /* CGI event parameters */
  48. #define kCGIpath_args            '----'
  49. #define kCGIhttp_search_args    'kfor'
  50. #define kCGIusername            'user'
  51. #define kCGIpassword            'pass'
  52. #define kCGIfrom_user            'frmu'
  53. #define kCGIclient_address        'addr'
  54. #define kCGIpost_args            'post'
  55. #define kCGImethod                'meth'
  56. #define kCGIserver_name            'svnm'
  57. #define kCGIserver_port            'svpt'
  58. #define kCGIscript_name            'scnm'
  59. #define kCGIcontent_type        'ctyp'
  60. #define kCGIreferer                'refr'
  61. #define kCGIuser_agent            'Agnt'
  62. #define kCGIaction                'Kact'
  63. #define kCGIaction_path            'Kapt'
  64. #define kCGIclient_ip            'Kcip'
  65. #define kCGIfull_request        'Kfrq'
  66. #define kCGIversion                'Pvrs'
  67. #define kCGIconnection            'Kcid'
  68.  
  69. /* for an official listing of the maximum sizes for CGI parameters,
  70.     <http://www.biap.com/datapig/mrwheat/cgi_params.html> */
  71. #define kCGIMaxpath_args        1024
  72. #define kCGIMaxhttp_search_args    1024
  73. #define kCGIMaxusername            32
  74. #define kCGIMaxpassword            32
  75. #define kCGIMaxfrom_user        128
  76. #define kCGIMaxclient_address    256
  77. #define kCGIMaxpost_args        32768
  78. #define kCGIMaxmethod            32
  79. #define kCGIMaxserver_name        256        /* server address? */
  80. #define kCGIMaxserver_port        16
  81. #define kCGIMaxscript_name        1024
  82. #define kCGIMaxcontent_type        64
  83. #define kCGIMaxreferer            1024
  84. #define kCGIMaxuser_agent        256
  85. #define kCGIMaxaction            32
  86. #define kCGIMaxaction_path        1024
  87. #define kCGIMaxclient_ip        32
  88. #define kCGIMaxfull_request        4096
  89. #define kCGIMaxversion            32768    /* ••• missing the correct value */
  90. #define kCGIMaxconnection        4
  91.  
  92. /* Send Partial event */
  93. #define kMyAESendPartial        'SPar'
  94.  
  95. #define kCGIPartialData            '----'
  96. #define kConnectionIDKeyword    'Kcid'
  97. #define kMoreKeyword            'Kmor'
  98.  
  99. #define kCGIPartialStartString    "<SEND_PARTIAL>"
  100.  
  101.  
  102. /***  TYPE DECLARATIONS  ***/
  103.  
  104. #if kCompileWithCGIFormHandling
  105. typedef struct
  106. {
  107.     char *    name;
  108.     char *    value;
  109. } CGIFormField;
  110. #endif
  111.  
  112. #if kCompileWithCGImethod
  113. typedef enum
  114. {
  115.     HTTP_UNDEFINED,
  116.     HTTP_get,
  117.     HTTP_post,
  118.     HTTP_getConditional
  119. } HTTPMethod;
  120. #endif
  121.  
  122. typedef struct
  123. {
  124.     /* the following fields should be treated as public read-only */
  125.     
  126.     #if kCompileWithCGIpath_args
  127.     char *        path_args;            /* '----' path_args            */
  128.     #endif
  129.     #if kCompileWithCGIhttp_search_args
  130.     char *        http_search_args;    /* 'kfor' http_search_args    */
  131.     #endif
  132.     #if kCompileWithCGIusername
  133.     char    username[kCGIMaxusername];    /* 'user' username            */
  134.     #endif
  135.     #if kCompileWithCGIpassword
  136.     char    password[kCGIMaxpassword];    /* 'pass' password            */
  137.     #endif
  138.     #if kCompileWithCGIfrom_user
  139.     char *        from_user;            /* 'frmu' from_user            */
  140.     #endif
  141.     #if kCompileWithCGIclient_address
  142.     char *        client_address;        /* 'addr' client_address    */
  143.     #endif
  144.     #if kCompileWithCGIpost_args
  145.     char *        post_args;            /* 'post' post_args            */
  146.     #endif
  147.     #if kCompileWithCGImethod
  148.     HTTPMethod    method;                /* 'meth' method            */
  149.     #endif
  150.     #if kCompileWithCGIserver_name
  151.     char *        server_name;        /* 'svnm' server_name        */
  152.     #endif
  153.     #if kCompileWithCGIserver_port
  154.     short        server_port;        /* 'svpt' server_port        */
  155.     #endif
  156.     #if kCompileWithCGIscript_name
  157.     char *        script_name;        /* 'scnm' script_name        */
  158.     #endif
  159.     #if kCompileWithCGIcontent_type
  160.     char *        content_type;        /* 'ctyp' content_type        */
  161.     #endif
  162.     #if kCompileWithCGIreferer
  163.     char *        referer;            /* 'refr' referer            */
  164.     #endif
  165.     #if kCompileWithCGIuser_agent
  166.     char *        user_agent;            /* 'Agnt' user_agent        */
  167.     #endif
  168.     
  169.     #if kCompileWithCGIActionSupport
  170.     char    action[kCGIMaxaction];    /* 'Kact' action            */
  171.     char *        action_path;        /* 'Kapt' action_path        */
  172.     #endif
  173.     
  174.     #if kCompileWithCGIclient_ip
  175.     char    client_ip[kCGIMaxclient_ip];    /* 'Kcip' client_ip            */
  176.     #endif
  177.     #if kCompileWithCGIfull_request
  178.     char *        full_request;        /* 'Kfrq' full_request        */
  179.     #endif
  180.     #if kCompileWithCGIversion
  181.     char *        version;            /* 'Pvrs' version            */
  182.     #endif
  183.     
  184.     #if kCompileWithCGISendPartial
  185.     long        connection;            /* 'Kcid' connection        */
  186.     #endif
  187.     
  188.     #if kCompileWithCGIFormHandling
  189.     CGIFormField *    formFields;        /* the fields from form submission */
  190.     long            totalFields;    /* total number of fields    */
  191.     #endif
  192.     
  193.     /* private fields that probably should not be touched outside
  194.         of the CGI.c file */
  195.     AppleEvent        appleEvent;        /* originating appleEvent    */
  196.     AppleEvent        replyEvent;        /* apple event reply record    */
  197.     
  198.     ThreadID        thread;            /* ID of the CGI handle's thread */
  199.     
  200.     /* public fields to be filled in */
  201.     char *        responseData;        /* data to return to the client        */
  202.     long        responseSize;        /* size in bytes of the response    */
  203. } CGIrecord;
  204.  
  205. typedef CGIrecord ** CGIHdl;
  206.  
  207.  
  208. /***  GLOBAL DECLARATIONS  ***/
  209.  
  210. #ifdef __CGISegment__
  211. #define _GLOBAL_    
  212. #else
  213. #define _GLOBAL_    extern
  214. #endif
  215.  
  216. /* these are globals for holding the standard http headers.
  217.     One of the headers must be prepended to the data returned in the Apple Event */
  218.  
  219. _GLOBAL_    Str255    gHTTPHeaderOK;            /* use data returned after header    */
  220. _GLOBAL_    Str255    gHTTPHeaderRedirect;    /* redirect client to different url    */
  221. _GLOBAL_    Str255    gHTTPHeaderErr;            /* an application level error        */
  222. #if kCompileWithCGISendPartial
  223. _GLOBAL_    Str255    gHTTPHeaderPush;        /* multipart server push            */
  224. #endif
  225.  
  226. _GLOBAL_    long    gHTTPHeaderOKSize;
  227. _GLOBAL_    long    gHTTPHeaderRedirectSize;
  228. _GLOBAL_    long    gHTTPHeaderErrSize;
  229. #if kCompileWithCGISendPartial
  230. _GLOBAL_    long    gHTTPHeaderPushSize;
  231. #endif
  232.  
  233. #undef _GLOBAL_
  234.  
  235.  
  236. /***  FUNCTION PROTOTYPES  ***/
  237.  
  238.         OSErr        InitCGIUtil                ( void );
  239.         
  240. #if kCompileWithCGIFormHandling
  241.         CGIFormField *    CGIFormFieldsFromArgs    ( char *, long *, short * );
  242.         CGIFormField *    CGIFormFieldsFindRecord    ( CGIHdl, char * );
  243.         void            CGIFormFieldsDispose    ( CGIFormField * );
  244. #endif    /* kCompileWithCGIFormHandling */
  245.         
  246.         void        CGIDecodeSpecialChars    ( char * );
  247.         char *        CGIEncodeSpecialChars    ( char * );
  248.         void        CGICharToHex            ( unsigned char, char * );
  249.  
  250. pascal    OSErr        CGIAESearchDoc        ( AppleEvent *, AppleEvent *, long );
  251.         
  252. #if kCompileWithCGISendPartial
  253.         OSErr        CGIAESendPartial    ( CGIHdl, char *, long, Boolean );
  254. #endif    /* kCompileWithCGISendPartial */
  255.  
  256.  
  257. /***  EXTERNAL FUNCTION PROTOTYPES  ***/
  258.  
  259.     /* this is the function which you must define for your particular application */
  260.     void        MyCGIProcess    ( CGIHdl );
  261.     
  262.     /* this function is called once at startup time.
  263.         Put any initialization you need to do in it. */
  264.     Boolean        MyCGIStartup    ( void );
  265.  
  266.     /* this function is called at quitting time.
  267.         Put any cleanup you need to do in it. */
  268.     Boolean        MyCGIQuit        ( Boolean );
  269.  
  270.  
  271. #else    /* if not kCompileWithCGICode */
  272.  
  273.     /* these are defined like this here so the StartupApplication function
  274.         doesn't have to be messed with when compiling without the CGI module */
  275.     #define InitCGIUtil()    (noErr)
  276.     #define MyCGIStartup()    (true)
  277.     #define MyCGIQuit()        (true)
  278.  
  279. #endif    /* kCompileWithCGICode */
  280.  
  281. /***  EOF  ***/
  282.